package com.easyattendance.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name="TBL_PROXY")
@IdClass(ProxyPK.class)
public class Proxy implements Serializable{
	
	@Id
	private Date proxy_date;
	
	@Id
	private String time_slot;
	
	@Id
	@GenericGenerator(name="teacher_id",strategy="foreign")
	private String subject_teacher_id;
	
	@Id
	@GenericGenerator(name="class_id",strategy="foreign")
	@Column(name="class_id",length=15,nullable=false)
	private String class_id;
	
	@GenericGenerator(name="subject_id",strategy="foreign")
	private String proxy_subject_id;

	@GenericGenerator(name="subject_id",strategy="foreign")
	private String subject_id; 
	
	@GenericGenerator(name="teacher_id",strategy="foreign")
	private String proxy_teacher_id;
	
	@GenericGenerator(name="section_id",strategy="foreign")
	@Column(name="section_id",length=10,nullable=false)
	private String section_id;

	/* Many to one realtionships in Proxy table */
	@ManyToOne
    @JoinColumn(name="subject_teacher_id", insertable=false, updatable=false, referencedColumnName="teacher_id")
    private Teacher subjectTeacher;
	
	@ManyToOne
    @JoinColumn(name="proxy_teacher_id", insertable=false, updatable=false, referencedColumnName="teacher_id")
    private Teacher proxyTeacher;
	
	@ManyToOne
    @JoinColumn(name="proxy_subject_id", insertable=false, updatable=false, referencedColumnName="subject_id")
    private Subject proxySubject;
	
	@ManyToOne
    @JoinColumn(name="subject_id",insertable=false, updatable=false,referencedColumnName="subject_id")
    private Subject subject;
	
	@ManyToOne
    @JoinColumn(name="section_id", insertable=false, updatable=false, referencedColumnName="section_id")
    private Section department;
	
	@ManyToOne
    @JoinColumn(name="class_id", insertable=false, updatable=false, referencedColumnName="class_id")
    private Class classObj;

	public Proxy() {
		super();
	}
	public Proxy(Date proxy_date, String time_slot, String subject_teacher_id,
			String proxy_subject_id,String subject_id, String proxy_teacher_id, String section_id,
			String class_id, Teacher subjectTeacher, Teacher proxyTeacher,
			Subject proxySubject, Subject subject, Section department, Class classObj) {
		super();
		this.proxy_date = proxy_date;
		this.time_slot = time_slot;
		this.subject_teacher_id = subject_teacher_id;
		this.proxy_subject_id = proxy_subject_id;
		this.subject_id=subject_id;
		this.proxy_teacher_id = proxy_teacher_id;
		this.section_id = section_id;
		this.class_id = class_id;
		this.subjectTeacher = subjectTeacher;
		this.proxyTeacher = proxyTeacher;
		this.proxySubject = proxySubject;
		this.subject = subject;
		this.department = department;
		this.classObj = classObj;
	}

	public Proxy(Date proxy_date, String time_slot, Teacher subjectTeacher,
			Teacher proxyTeacher, Subject proxySubject, Subject subject, Section department,
			Class classObj) {
		super();
		this.proxy_date = proxy_date;
		this.time_slot = time_slot;
		this.subjectTeacher = subjectTeacher;
		this.proxyTeacher = proxyTeacher;
		this.proxySubject = proxySubject;
		this.subject = subject;
		this.department = department;
		this.classObj = classObj;
	}
	
	
	public Proxy(Date proxy_date, String time_slot, String subject_teacher_id,
			String proxy_subject_id, String subject_id,String proxy_teacher_id,String class_id,
			String section_id) {
		super();
		this.proxy_date = proxy_date;
		this.time_slot = time_slot;
		this.subject_teacher_id = subject_teacher_id;
		this.proxy_subject_id = proxy_subject_id;
		this.subject_id=subject_id;
		this.proxy_teacher_id = proxy_teacher_id;
		this.class_id = class_id;
		this.section_id = section_id;
		
	}
	public Date getProxy_date() {
		return proxy_date;
	}

	public void setProxy_date(Date proxy_date) {
		this.proxy_date = proxy_date;
	}

	public String getTime_slot() {
		return time_slot;
	}

	public void setTime_slot(String time_slot) {
		this.time_slot = time_slot;
	}

	
	public String getSubject_teacher_id() {
		return subject_teacher_id;
	}



	public void setSubject_teacher_id(String subject_teacher_id) {
		this.subject_teacher_id = subject_teacher_id;
	}



	public String getProxy_subject_id() {
		return proxy_subject_id;
	}



	public void setProxy_subject_id(String proxy_subject_id) {
		this.proxy_subject_id = proxy_subject_id;
	}



	public String getProxy_teacher_id() {
		return proxy_teacher_id;
	}



	public void setProxy_teacher_id(String proxy_teacher_id) {
		this.proxy_teacher_id = proxy_teacher_id;
	}



	public Teacher getSubjectTeacher() {
		return subjectTeacher;
	}

	public void setSubjectTeacher(Teacher subjectTeacher) {
		this.subjectTeacher = subjectTeacher;
	}

	public Teacher getProxyTeacher() {
		return proxyTeacher;
	}

	public void setProxyTeacher(Teacher proxyTeacher) {
		this.proxyTeacher = proxyTeacher;
	}

	public Subject getProxySubject() {
		return proxySubject;
	}
	public void setProxySubject(Subject proxySubject) {
		this.proxySubject = proxySubject;
	}
	public String getDept_id() {
		return section_id;
	}
	public void setDept_id(String section_id) {
		this.section_id = section_id;
	}
	public String getSem_year_id() {
		return class_id;
	}
	public void setSem_year_id(String class_id) {
		this.class_id = class_id;
	}
	public Section getSection() {
		return department;
	}
	public void setSection(Section department) {
		this.department = department;
	}
	/*public com.easyattendance.model.Class getClass() {
		return semYear;
	}*/
	public void setClass(Class classObj) {
		this.classObj = classObj;
	}
	
	public String getSection_id() {
		return section_id;
	}
	public void setSection_id(String section_id) {
		this.section_id = section_id;
	}
	public String getClass_id() {
		return class_id;
	}
	public void setClass_id(String class_id) {
		this.class_id = class_id;
	}
	public Subject getSubject() {
		return subject;
	}
	public void setSubject(Subject subject) {
		this.subject = subject;
	}
	public Class getClassObj() {
		return classObj;
	}
	public void setClassObj(Class classObj) {
		this.classObj = classObj;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((proxy_date == null) ? 0 : proxy_date.hashCode());
		result = prime
				* result
				+ ((proxy_subject_id == null) ? 0 : proxy_subject_id.hashCode());
		result = prime
				* result
				+ ((proxy_teacher_id == null) ? 0 : proxy_teacher_id.hashCode());
		result = prime * result
				+ ((class_id == null) ? 0 : class_id.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Proxy other = (Proxy) obj;
		if (proxy_date.equals(other.proxy_date) && proxy_subject_id.equals(other.proxy_subject_id)
					&& proxy_teacher_id.equals(other.proxy_teacher_id) &&  class_id.equals(other.class_id)) {
			return true;
		}
		return false;
	}
	
	
}
